//

//  ByAddressListCell.m

//  caipiao_ios

//

//  Created by mc on 2018/7/19.

//  Copyright © 2018年 ZhangZhanbin. All rights reserved.

//



#import "ByAddressListCell.h"



@implementation ByAddressListCell



+ (instancetype)cellWithTableView:(UITableView*)tableView{
    
    
    
    static NSString *cellIdentifier = @"ByAddressListCell";
    
    ByAddressListCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    
    if (cell == nil) {
        
        cell = [[self alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
        
    }
    
    return cell;
    
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        self.selectionStyle = UITableViewCellSeparatorStyleNone;
        
        [self initViews];
        
    }
    
    return self;
    
}





- (void)initViews{
    
    
    
    [self.contentView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    
    
    
    UILabel *nameLabel = [[UILabel alloc] init];
    
    [self.contentView addSubview:nameLabel];
    
    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.contentView).offset(10);
        
        make.left.equalTo(self.contentView).offset(20);
        
        make.size.mas_equalTo(CGSizeMake(80, 20));
        
    }];
    
    nameLabel.textColor = [UIColor grayColor];
    
    nameLabel.font = FONT(14);
    
    nameLabel.text = @"张占彬";
    
    
    
    UILabel *phoneLabel = [[UILabel alloc] init];
    
    [self.contentView addSubview:phoneLabel];
    
    [phoneLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(nameLabel.mas_top).offset(0);
        
        make.left.equalTo(nameLabel.mas_right).offset(10);
        
        make.right.equalTo(self.contentView).offset(-10);
        
        make.height.mas_equalTo(@20);
        
    }];
    
    phoneLabel.textColor = [UIColor grayColor];
    
    phoneLabel.font = FONT(12);
    
    phoneLabel.text = @"15868405030";
    
    
    
    
    
    UILabel *addressLabel = [[UILabel alloc] init];
    
    [self.contentView addSubview:addressLabel];
    
    [addressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(nameLabel.mas_left).offset(0);
        
        make.right.equalTo(self.contentView).offset(-20);
        
        make.top.equalTo(nameLabel.mas_bottom).offset(2);
        
        make.height.mas_equalTo(@18);
        
    }];
    
    addressLabel.textColor = [UIColor grayColor];
    
    addressLabel.font = FONT(12);
    
    addressLabel.text = @"浙江省杭州市江干区xxx大厦";
    
    
    
    UILabel *line = [[UILabel alloc] init];
    
    [self.contentView addSubview:line];
    
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.contentView).offset(0);
        
        make.right.equalTo(self.contentView).offset(0);
        
        make.top.equalTo(addressLabel.mas_bottom).offset(9);
        
        make.height.mas_equalTo(@1);
        
    }];
    
    line.backgroundColor = BY_LINE_COLOR;
    
    
    
    
    
    UIView *backgroundView = [[UIView alloc] init];
    
    [self.contentView addSubview:backgroundView];
    
    backgroundView.backgroundColor = [UIColor whiteColor];
    
    [backgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.contentView).offset(0);
        
        make.right.equalTo(self.contentView).offset(0);
        
        make.top.equalTo(line.mas_bottom).offset(0);
        
        make.bottom.equalTo(self.contentView).offset(0);
        
    }];
    
    
    
    UIView *deleteView = [[UIView alloc] init];
    
    [backgroundView addSubview:deleteView];
    
    [deleteView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.equalTo(backgroundView).offset(-10);
        
        make.centerY.equalTo(backgroundView).offset(0);
        
        make.size.mas_equalTo(CGSizeMake(60, 20));
        
    }];
    
    
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    
    [deleteView addGestureRecognizer:tap];
    
    deleteView.tag = 100;
    
    
    
    
    
    UIImageView *deleteBtn = [[UIImageView alloc] init];
    
    [deleteView addSubview:deleteBtn];
    
    [deleteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(deleteView).offset(0);
        
        make.centerY.equalTo(deleteView).offset(0);
        
        make.size.mas_equalTo(CGSizeMake(12, 12));
        
    }];
    
    deleteBtn.image = [UIImage imageNamed:@"qingchu"];
    
    
    
    
    
    UILabel *titleLabel = [[UILabel alloc] init];
    
    [deleteView addSubview:titleLabel];
    
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(deleteBtn.mas_right).offset(3);
        
        make.centerY.equalTo(deleteView).offset(0);
        
        make.height.mas_equalTo(@15);
        
        make.right.equalTo(deleteView).offset(0);
        
    }];
    
    titleLabel.text = @"删除";
    
    titleLabel.font = FONT(12);
    
    titleLabel.textColor = [UIColor lightGrayColor];
    
    titleLabel.textAlignment = NSTextAlignmentLeft;
    
    
    
    
    
    UIView *editView = [[UIView alloc] init];
    
    [backgroundView addSubview:editView];
    
    [editView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.equalTo(deleteView.mas_left).offset(-20);
        
        make.centerY.equalTo(backgroundView).offset(0);
        
        make.size.mas_equalTo(CGSizeMake(60, 20));
        
    }];
    
    
    
    UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    
    [editView addGestureRecognizer:tap1];
    
    editView.tag = 200;
    
    
    
    
    
    UIImageView *editBtn = [[UIImageView alloc] init];
    
    [editView addSubview:editBtn];
    
    [editBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(editView).offset(0);
        
        make.centerY.equalTo(editView).offset(0);
        
        make.size.mas_equalTo(CGSizeMake(12, 12));
        
    }];
    
    editBtn.image = [UIImage imageNamed:@"bianji"];
    
    
    
    
    
    UILabel *editLabel = [[UILabel alloc] init];
    
    [editView addSubview:editLabel];
    
    [editLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(editBtn.mas_right).offset(3);
        
        make.centerY.equalTo(editView).offset(0);
        
        make.height.mas_equalTo(@15);
        
        make.right.equalTo(editView).offset(0);
        
    }];
    
    editLabel.text = @"编辑";
    
    editLabel.font = FONT(12);
    
    editLabel.textColor = [UIColor lightGrayColor];
    
    editLabel.textAlignment = NSTextAlignmentLeft;
    
    
    
    
    
    UIButton *selectBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    
    [backgroundView addSubview:selectBtn];
    
    [selectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(backgroundView).offset(10);
        
        make.centerY.equalTo(backgroundView).offset(0);
        
        make.size.mas_equalTo(CGSizeMake(20, 20));
        
    }];
    
    [selectBtn setImage:[UIImage imageNamed:@"morendizhiweixuanzhong"] forState:UIControlStateNormal];
    
    [selectBtn setImage:[UIImage imageNamed:@"morendizhixuanzhong"] forState:UIControlStateSelected];
    
    
    
    
    
    UILabel *noteLabel = [[UILabel alloc] init];
    
    [backgroundView addSubview:noteLabel];
    
    [noteLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(selectBtn.mas_right).offset(5);
        
        make.centerY.equalTo(backgroundView).offset(0);
        
        make.size.mas_equalTo(CGSizeMake(160, 10));
        
    }];
    
    noteLabel.font = FONT(12);
    
    noteLabel.textColor = BY_TEXT_COLOR;
    
    noteLabel.text = @"默认地址";
    
}



- (void)tapAction:(UITapGestureRecognizer *)tap{
    
    if (tap.view.tag == 100) {
        
        if (self.deleteBlock) {
            
            self.deleteBlock();
            
        }
        
    }else if (tap.view.tag == 200){
        
        if (self.editBlock) {
            
            self.editBlock();
            
        }
        
    }
    
    
    
}





@end
